﻿@{
    ViewBag.Title = "用户列表";
}

<div class="layui-btn-group actionTable">
    <a class="layui-btn" href="@Url.Action("Add")">添加</a>
</div>

<table class="layui-table" lay-data="{url:'@Url.Action("GetData")', page:true}" lay-filter="demo">
    <thead>
        <tr>
            <th lay-data="{type:'numbers'}"></th>
            <th lay-data="{field:'a.user_name'}">用户名</th>
            <th lay-data="{field:'a.emp_code'}">工号</th>
            <th lay-data="{field:'a.real_name'}">姓名</th>
            <th lay-data="{field:'role_name'}">角色</th>
            <th lay-data="{field:'a.create_date', templet: function(d){return moment(d.create_date).format('YYYY-MM-DD')} }">更新时间</th>
            <th lay-data="{align:'center', toolbar: '#toolbar'}">操作</th>
        </tr>
    </thead>
</table>

<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

@section scripts{
    <script>
        layui.use('table', function () {
            var table = layui.table;
            //监听表格复选框选择
            table.on('checkbox(demo)', function (obj) {
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();
                        layer.close(index);
                        $.post("@Url.Action("Delete")", { id: data.Id }, function (result) {
                            if (!result.success) {
                                layer.msg(result.message, { icon: 2 });
                            }
                        });
                    });
                } else if (obj.event === 'edit') {
                    document.location.href = "@Url.Action("Add")" + data.Id;
                }
            });

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
}